<?php 
	namespace Admin\Controller;
	
	class NodeController extends AdminController{
		private $_model = null; //数据库操作类

		//初始化操作
		public function _initialize(){
			parent::_initialize();
			$this->_model = D('Node');
		}

		//列表详情
		public function index()
		{
			$search = I('get.name');
			if(empty($search)) {
				$count = $this->_model->order('id desc')->count();
				$Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
				$show = $Page->show();// 分页显示输出
				//查询数据
				$list = $this->_model->limit($Page->firstRow.','.$Page->listRows)->order('id desc')->select();

				//分配变量
				$this->assign("list",$list);
				$this->assign("page",$show);
				//加载模板
				$this->display();
				exit;
			}

			$count = $this->_model->where('name like "%'.$search.'%"')->order('id desc')->count();
			$Page = new \Think\Page($count,3);// 实例化分页类 传入总记录数和每页显示的记录数(25)

			$map['name'] = $_GET['name'];
			// var_dump($map);
			$Page->parameter=$map;
			$show = $Page->show();// 分页显示输出
			//查询数据
			$list = $this->_model->where('name like "%'.$search.'%"')->limit($Page->firstRow.','.$Page->listRows)->order('id desc')->select();
			// var_dump($list);exit;

			//分配变量
			$this->assign("list",$list);
			$this->assign("page",$show);
			//加载模板
			$this->display();
		}


		public function add()
		{
			$this->display();
		}

		//执行添加操作
		public function doadd(){

			if(!$this->_model->create()){
				$this->error($this->_model->getError());
				exit;
			}

			if($this->_model->add() > 0){
				$this->success("添加成功！",U('Node/index'));
			}else{
				$this->error("添加失败！");
			}
		}


		//删除操作
		public function del(){
			if($this->_model->delete($_GET['id']) > 0){
				$this->success("删除成功！",U('Node/index'));
			}else{
				$this->error("删除失败");
			}
		}

		//加载修改页面c 
		public function edit(){
			//查出数据
			$vo = $this->_model->where(array('id'=>array('eq',I('id'))))->find();
			//向模板分配数据
			$this->assign('vo',$vo);
			//加载模板
			$this->display();
		}

		//执行修改操作
		public function save(){
			// var_dump($this->_model->create());exit;
			//初始化
			if(!$this->_model->create()){
				$this->error($this->_model->getError());
				exit;
			}
			//执行修改 
			if($this->_model->save() >= 0){
				$this->success("修改成功！",U('Node/index'));
			}else{
				$this->error("修改失败");
			}
		}



		public function doajax()
		{
			$id=I('post.id');
			$status = $this->_model->field('status')->where('id='.$id)->find();
			if($status['status']==0) {
				$status['status']=1;
				$this->_model->where('id='.$id)->save($status);
				 echo "营业中";
			} else {
				$status['status']=0;
				$this->_model->where('id='.$id)->save($status);
				echo "未营业";
			}
		}

		
	}

 ?>